import string

class Instructions:
    def __init__(self, grs):
        self.grs = grs
        self.instrs = {
            'add16'   :  [3, ['w', 'w', 'w'], self.add16],
            'add16d'  :  [2, ['w', 'w'], self.add16d],
            'call'    :  [1, ['u'], self.call],
            'subb64'  :  [3, ['u', 'u', 'u'], self.subb64]
        }
    
    def add16(self, x):
        regs = []
        for i in range(3):
            regs += [self.get_regs_num(x[i])]
        tmp = self.grs.read_gr16(regs[1]) + self.grs.read_gr16(regs[2])
        self.grs.write_gr16(tmp & 0xFFFF, regs[0])
        
    def add16d(self, x):
        regs = []
        for i in range(2):
            regs += [self.get_regs_num(x[i])]
        tmp = self.grs.read_gr16(regs[0]) + self.grs.read_gr16(regs[1])
        self.grs.write_gr16(tmp & 0xFFFF, regs[0])
        
    def call(self, x):
        return
    
    def subb64(x):
        return
    
    def get_regs_num(self, argv):
        if argv != '':
            if argv[0] in ['w', 'u', 'v']:
                return string.atoi(argv[1:])
        return argv